2#Import needed adjustment from modules.  The idea is that the different ordinances will use the 
#same type of calculation, just use different adjustment factors that will be stored outside of the main_module
#for easy editing.
import marin


#right now, I am exploring the use of EP's .dat file.
#future iterations will have the choice to enter the details manually
#as well as only open the file once.
def findCZArea():
    try:
        myfile = open('C:\\EP4\\Res Sample.dat','r')

        aString = myfile.read(437)
        R = aString.split('|')
        climateZone = int(R[4])
        area = int(R[18])
        myfile.close
        return (climateZone, area)
    except:
        print 'There is an error'
    
#The local ordinance has an adjustment factor to adjust standard t24 value in such a manner as to make compliance 
#more difficult.  adjustmentFactor() uses the area passed from findCZArea() to maked the appropriate house area category selection.
#Lastly, using the matrix in the marin.py module to pass the adjustment factor to calculate the adjusted Standard allotment.
def adjustmenFactor():
    n = 0
    #cz_Adjust = [[0.850, 0.825, 0.700, 0.630, 0.570, 0.525, 0.485, 0.450, 0.425],
    #         [0.850, 0.850, 0.730, 0.665, 0.605, 0.560, 0.520, 0.485, 0.460]]
    (climate_zone, area) = findCZArea()
        
    if area > 11500:
        n=8
    elif area in range(10500,11500):
        n=7
    elif area in range(9500,10500):
        n=6    
    elif area in range(8500,9500):
        n=5
    elif area in range(7500,8500):
        n=4    
    elif area in range(6500,7500):
        n=3
    elif area in range(5500,6500):
        n=2
    elif area in range(4500,5500):
        n=1
    elif area in range(1500,4500):
        n=0
    else:
        print 'Your climate zone or floor area do not meet the minimum requirements'
        return None
    return marin.cz_Adjust[climate_zone - 2][n]


def stanpropGoGetter():
    myfile = open('C:\\EP4\\Res Sample.dat','r')

    aString = myfile.read(437)
    R = aString.split('|')
    standardT24 = float(R[37])
    proposedT24 = float(R[50])
    myfile.close
    
    return(standardT24, proposedT24)



def calc_compliance():
    (standardT24, proposedT24) = stanpropGoGetter()
    
    revisedStandard = adjustmenFactor() * standardT24
    
    print 'Standard: ', revisedStandard
    print 'Proposed: ', proposedT24
    
    
    if revisedStandard < proposedT24:
        print 'Your house does not comply '
    else:
        print 'Your house complies'
    
#user_select will prompt the user to select whether or not
#to use the automatic .dat reader or to input the details manually
#and eventually select what Ordinance to run.        
def user_select():
    print 'Welcome to the Local Ordinance Calculator'
    is_solar = int(raw_input("Will you be installing solar panels? Enter 1 for yes, 2 for no"))
    is_dat = int(raw_input("To enter data manually, enter 1.  To use EnergyPro's .dat file, enter 2"))
    
    return(is_solar, is_dat)
 
def user_input():
    climate_zone = int(raw_input('Input in your climate zone: '))
    
    
    
def master_mind():
    (is_solar, is_dat) = user_select()
    
    if is_dat == 1:
        (climate_zone) = user_input()
        
    elif is_dat == 2:
        calc_compliance()
    else:
        
        
    
        

if __name__ == "__main__":
    master_mind()
    